<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@ page session="true" %>
<%@ page import="javax.portlet.*"%>
<%@ page import="java.util.List" %>
<%@ page import="pits.dao.TakenCourseBriefDAO" %>
<%@ page import="pits.dto.TakenCourseBriefDTO" %>
<%@ page import="pits.dao.TakenProjectBriefDAO" %>
<%@ page import="pits.dto.TakenProjectBriefDTO" %>
<%@ page import="pits.util.Constants" %>
<%@ taglib uri="http://java.sun.com/portlet" prefix="portlet"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<portlet:defineObjects />

<html>

<script type="text/javascript">
	countTCmp = 0;
	pageTCmp = 1;

	function isIn(container, str, splitter) {
		var arr = container.split(splitter);
		for (i = 0; i < arr.length; i++) {
			if (arr[i] == str) return true;
		}
		return false; 
	}
	
	function getForm(namespace, name) {
			return document.forms[namespace + name];
	}

	function submitForm(namespace, name, action, page) {
			var frm = getForm(namespace, name);
			frm.txtAction.value = action;
			frm.submitLink.value = page;
			frm.submit();
	}

	function setDepartID(namespace, name, departID) {
			var frm = getForm(namespace, name);
			frm.departID.value = departID;
			return;
	}
	function addPageTCmp(num) {
		if (num=="-1") {
			pageTCmp--;
		} else {
			pageTCmp++;
		}
		return;
	}
	function paging() {
		for (i = 0; i < countTCmp; i++) {
			id = "exp" + i;
			if (i==5*pageTCmp-1 || i == 5*pageTCmp-2 || i == 5*pageTCmp-3 
					|| i == 5*pageTCmp-4 || i == 5*pageTCmp-5) {
				document.getElementById(id).style.display="inline";
			} else {
				document.getElementById(id).style.display="none";
			};
		};
		if (pageTCmp==1) {
			document.getElementById("pageRowFirst").style.display="inline";
			document.getElementById("pageRowMiddle").style.display="none";
			document.getElementById("pageRowLast").style.display="none";
		} else {
			if (countTCmp/5>pageTCmp-1 && countTCmp/5<=pageTCmp) {
				document.getElementById("pageRowFirst").style.display="none";
				document.getElementById("pageRowMiddle").style.display="none";
				document.getElementById("pageRowLast").style.display="inline";
			} else {
				document.getElementById("pageRowFirst").style.display="none";
				document.getElementById("pageRowMiddle").style.display="inline";
				document.getElementById("pageRowLast").style.display="none";
			};
		};
		return;
	}
</script>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Personal Information Tracking System</title>
<meta name="keywords" content="" />
<meta name="description" content="" />

<script type="text/javascript" src="simpletreemenu.js">
/***********************************************
* Simple Tree Menu- Â© Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>

<link rel="stylesheet" type="text/css" href="style/simpletree.css" />
<link href="style/style.css" rel="stylesheet" type="text/css" media="screen" /></head>

<body>
<form name="<portlet:namespace/>myForm" action="<portlet:actionURL/>" method="POST">
<input type="hidden" name="txtAction"/>
<input type="hidden" name="submitLink"/>
<p align="right">
	You are logging in as 
	<a href="#" onclick="submitForm('<portlet:namespace/>', 'myForm', 'getEmployeeInfo', 'EmployeeStatInfo.jsp')"><b>${sessionScope.userName}</b></a>
	! &nbsp;
	<%
	if (session.getAttribute("userRole").equals("pm")) {
	%>
		<a href="#" onclick="submitForm('<portlet:namespace/>', 'myForm', 'search', 'EmployeeStatInfo.jsp')">Search</a>&nbsp; | 
	<%
	}
	%>
	<a href="#" onclick="submitForm('<portlet:namespace/>', 'myForm', 'home', 'EmployeeStatInfo.jsp')">Home</a>
	| &nbsp;
	<a href="#" onclick="submitForm('<portlet:namespace/>', 'myForm', 'logout', 'EmployeeStatInfo.jsp')">Logout</a>
</p>
</form>
<table>
	<tr>			
		<td>
			<table border="1">
				<tr>
					<td><h4 align="center" style="color: #FF0000">${sessionScope.successMess} ${sessionScope.errorMess}</h4></td>
				</tr>
				<tr>
					<td><h2 class="title">Employee Information </h2></td>
				</tr>
				<tr>
					<td><em>Personal Information </em></td>
				</tr>
				<tr>
					<td>
					<form name="<portlet:namespace/>employeeStatInfoForm" action="<portlet:actionURL/>" method="POST">
						<input type="hidden" name="txtAction"/>
						<input type="hidden" name="submitLink"/>
						<input type="hidden" id="page" value="1"/>
						<table border="1" width="100%">
							<tr>								
								<td align="center" valign="middle">ID</td>
								<td align="center" valign="middle">Name</td>
								<td align="center" valign="middle">Birthdate</td>
								<td align="center" valign="middle">Address</td>
								<td align="center" valign="middle">Email</td>
								<td align="center" valign="middle">Phone</td>						
								<td align="center" valign="middle"><div align="center">Action</div></td>
							</tr>
							<tr>
								<td align="center">${sessionScope.employee.empID}</td>
								<td align="left">${sessionScope.employee.name}</td>
								<td align="center">${sessionScope.employee.birthday}</td>
								<td align="left">${sessionScope.employee.address}</td>
								<td align="left">${sessionScope.employee.email}</td>
								<td align="left">${sessionScope.employee.phone}</td>
								<td align="center" valign="middle">
									<input type="button" value="Edit" 
										 	onclick="submitForm('<portlet:namespace/>','employeeStatInfoForm',
										 						 'editEmployee', 'EmployeeStatInfo.jsp')"/>
								</td>
							</tr>							
						</table>
						</form>
					</td>
				</tr>
<!------------------------------------------------------Taken Companies' Information Part----------------------------------------------------->
				<tr>
					<td><em>Experience</em></td>
				</tr>
				<tr>
					<td>
					<form name="<portlet:namespace/>takenCompanyInfoForm" action="<portlet:actionURL/>" method="POST">
					<input type="hidden" name="txtAction"/>
					<input type="hidden" name="submitLink"/>
					<input type="hidden" name="departID"/>
						<table border="1" width="100%">
							<tr>
								<td align="center" valign="middle">&nbsp;Check&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Company&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Address&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Phone&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Department&nbsp;</td>
								<td align="center" valign="middle">&nbsp;StartDate&nbsp;</td>
								<td align="center" valign="middle">&nbsp;EndDate&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Role&nbsp;</td>
								<td align="center" valign="middle">&nbsp;Short Description&nbsp;</td>
								<td align="center" valign="middle"><div align="center">&nbsp;Action&nbsp;</div></td>										
							</tr>
							<% int countTCmp = 0; %>
							<c:forEach items="${sessionScope.employee.departexps}" var="exp">
								<tr id="exp<%=countTCmp %>">
									<td align="center">
										<input type="checkbox" name="selectDepart${exp.department.departID}"/> 
									</td>
									<td align="left"><a href="#">${exp.department.company.comName}</a></td>
									<td align="left">${exp.department.company.address}</td>
									<td align="left">${exp.department.company.phone}</td>
								 	<td align="left">${exp.department.departName}</td>
								 	<td align="left">${exp.startDate}</td>
									<td align="left">${exp.endDate}</td>
									<td align="center">${exp.role.role}</td>
									<td align="left">
									<script type="text/javascript">
										if ('${exp.description}'=='') {
											document.write("<div align='center'>-</div>");
										} else {
											document.write("${exp.description}");
										};
									</script>
									</td>
									<td align="center" valign="middle">
										<a 	href="#" onclick="setDepartID('<portlet:namespace/>', 'takenCompanyInfoForm', '${exp.department.departID}');
														submitForm('<portlet:namespace/>', 'takenCompanyInfoForm', 
																	'editTakenCompany', 'EmployeeStatInfo.jsp')">Edit</a>
									</td>
								</tr>
								<script type="text/javascript">
									countTCmp++;
								</script>
								<% countTCmp++; %>
							</c:forEach>
							<tr id="pageRowFirst"><td colspan="10" align="center">
								&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
								<a href='#' onclick="addPageTCmp(1); paging();">Next</a>
							</td>
							</tr>
							<tr id="pageRowMiddle"><td colspan="10" align="center">
								<a href='#' onclick="addPageTCmp(-1); paging()">Prev</a>&nbsp;
								&nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;
								&nbsp;<a href='#' onclick="addPageTCmp(1); paging();">Next</a>
							</td></tr>
							<tr id="pageRowlast"><td colspan="10" align="center">
								<a href='#' onclick="addPageTCmp(-1); paging();">Prev</a>&nbsp;
								&nbsp;&nbsp;&nbsp;||&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
								<script type="text/javascript">
								paging();
								if (countTCmp>5) {
									paging();
								} else {
									document.getElementById("pageRowFirst").style.display="none";
									document.getElementById("pageRowMiddle").style.display="none";
									document.getElementById("pageRowLast").style.display="none";
								};
								</script>
							</td></tr>
							<tr>
								<td colspan="10" align="left" valign="middle">
									<input type="button" value="Add" 
											onclick="submitForm('<portlet:namespace/>','takenCompanyInfoForm',
													'addTakenCompany','EmployeeStatInfo.jsp')"/>
									<input type="button" value="Delete" 
											onclick="submitForm('<portlet:namespace/>','takenCompanyInfoForm',
													'deleteTakenCompany','EmployeeStatInfo.jsp')"/>
								</td>
							</tr>
						</table>
					</form>
					</td>
				</tr>
<!------------------------------------------------------Taken Courses' Information Part----------------------------------------------------->
				<tr>
					<td><em>Taken Course(s)</em></td>
				</tr>
				
				<tr>
					<td>
					<form name="<portlet:namespace/>takenCourseInfoForm" action="<portlet:actionURL/>" method="POST">
					<input type="hidden" name="txtAction"/>
					<input type="hidden" name="submitLink"/>
					<input type="hidden" name="courseID"/>
					<input type="hidden" name="deleteCourseList" value=""/>
						<table border="1" width="100%">
							<tr align="center" valign="middle">
								<td rowspan="2">&nbsp;Check&nbsp;</td>
								<td rowspan="2">&nbsp;Name&nbsp;</td>
								<td rowspan="2">&nbsp;Department/Institute Issued&nbsp;</td>
								<td rowspan="2">&nbsp;Period (day)&nbsp;</td>
								<td rowspan="2">&nbsp;Description&nbsp;</td>
								<td colspan="3">&nbsp;Technology&nbsp;</td>
								<td rowspan="2">&nbsp;Grade&nbsp;</td>
								<td rowspan="2">&nbsp;Date issued&nbsp;</td>					
								<td rowspan="2">&nbsp;Action&nbsp;</td>										
							</tr>
							<tr align="center" valign="middle">
								<td>Language</td>
								<td>Framework/Technology</td>
								<td>DBMS</td>
							</tr>
							
							<%
							List<TakenCourseBriefDTO> takenCourseList = new TakenCourseBriefDAO().getData("" + session.getAttribute("empID"));
							for (int i = 0; i < takenCourseList.size(); i++) {
							%>
							<tr>
								<td align="center">
									<label><input type="checkbox" value='<%=takenCourseList.get(i).getCourseID() %>' onclick="
										if (isIn(this.form.deleteCourseList.value, this.value, ':') && this.checked == false) {
											this.form.deleteCourseList.value = this.form.deleteCourseList.value.replace(':' + this.value, '');
											if (this.form.deleteCourseList.value.length == 0) {
												this.form.courseDelete.style.visibility = 'hidden';
											}
										}
										else if (!isIn(this.form.deleteCourseList.value, this.value, ':') && this.checked == true) {
											this.form.deleteCourseList.value += ':' + this.value;
											this.form.courseDelete.style.visibility = 'visible';
										}
									"/></label>
								</td>
								<td align="left" valign="middle">
									<a href="#" onclick="
										document.forms['<portlet:namespace/>takenCourseInfoForm'].courseID.value = '' + <%=takenCourseList.get(i).getCourseID() %>;
										submitForm('<portlet:namespace/>', 'takenCourseInfoForm', 'editCourseInfo', 'EmployeeStatInfo.jsp');
									">
										<%=takenCourseList.get(i).getName() %>
									</a>
								</td>
								<td align="left" align="center" valign="middle"><%=takenCourseList.get(i).getDepartName() %></td>
								<td align="left" valign="middle"><%=takenCourseList.get(i).getPeriod() %></td>
								<td align="left" valign="middle"><%=takenCourseList.get(i).getDescription() %></td>
								<td align="center" valign="middle"><%=takenCourseList.get(i).getLang() %></td>
								<td align="center" valign="middle"><%=takenCourseList.get(i).getFrameTech() %></td>
								<td align="center" valign="middle"><%=takenCourseList.get(i).getDBMS() %></td>
								<td align="center" valign="middle"><%=takenCourseList.get(i).getGrade() %></td>
								<td align="left" valign="middle"><%=takenCourseList.get(i).getDateIssused() %></td>
								<td align="center" valign="middle">
									<a 	href="#" onclick="
										document.forms['<portlet:namespace/>takenCourseInfoForm'].courseID.value = '' + <%=takenCourseList.get(i).getCourseID() %>;
										submitForm('<portlet:namespace/>', 'takenCourseInfoForm', 'editTakenCourse', 'EmployeeStatInfo.jsp');
									">
										Edit
									</a>
								</td>								
							</tr>
							<%}%>
							
							<tr>
								<td colspan="10" align="left" valign="middle">
									<input type="button" value="Add" 
											onclick="submitForm('<portlet:namespace/>','takenCourseInfoForm',
													'addTakenCourse','EmployeeStatInfo.jsp')"/>
									<input type="button" name="courseDelete" value="Delete" style="visibility: hidden" onclick="
										this.form.deleteCourseList.value = this.form.deleteCourseList.value.substr(1);
										submitForm('<portlet:namespace/>','takenCourseInfoForm','deleteTakenCourse','EmployeeStatInfo.jsp');
									"/>
								</td>
							</tr>
						</table>
					</form>
					</td>
				</tr>
<!------------------------------------------------------Taken Projects' Information Part----------------------------------------------------->
				<tr>
					<td><em>Taken Project(s)</em></td>
				</tr>
				<tr>
					<td>
					<form name="<portlet:namespace/>takenProjectInfoForm" action="<portlet:actionURL/>" method="POST">
					<input type="hidden" name="txtAction"/>
					<input type="hidden" name="submitLink"/>
					<input type="hidden" name="projectID"/>
					<input type="hidden" name="deleteProjectList" />
						<table border="1" width="100%">
							<tr align="center" valign="middle">
								<td><div align="center">&nbsp;Check&nbsp;</div></td>
								<td><div align="center">&nbsp;Project Name</div></td>
								<td><div align="center">&nbsp;Department&nbsp;</div></td>
								<td><div align="center">&nbsp;Start Date&nbsp;</div></td>							
								<td><div align="center">&nbsp;End Date&nbsp;</div></td>
								<td><div align="center">&nbsp;Role&nbsp;</div></td>
								<td><div align="center">&nbsp;Languages&nbsp;</div></td>
								<td><div align="center">&nbsp;Framework/Technology&nbsp;</div></td>
								<td><div align="center">&nbsp;Database&nbsp;</div></td>
								<td><div align="center">&nbsp;More Decriptions&nbsp;</div></td>
								<td><div align="center">&nbsp;Action&nbsp;</div></td>										
							</tr>
							
							<%
							List<TakenProjectBriefDTO> takenProjectList = new TakenProjectBriefDAO().getData("" + session.getAttribute("empID"));
							for (int i = 0; i < takenProjectList.size(); i++) {
							%>
							<tr>
								<td>
									<div align="center">
									<input type="checkbox" value='<%=takenProjectList.get(i).getProjectID() %>' onclick="
										if (isIn(this.form.deleteProjectList.value, this.value, ':') && this.checked == false) {
											this.form.deleteProjectList.value = this.form.deleteProjectList.value.replace(':' + this.value, '');
											if (this.form.deleteProjectList.value.length == 0) {
												this.form.projectDelete.style.visibility = 'hidden';
											}
										}
										else if (!isIn(this.form.deleteProjectList.value, this.value, ':') && this.checked == true) {
											this.form.deleteProjectList.value += ':' + this.value;
											this.form.projectDelete.style.visibility = 'visible';
										}
									" />
									</div>
								</td>
								
							 	<td align="left" valign="middle">
									<a href="#" onclick="
										document.forms['<portlet:namespace/>takenProjectInfoForm'].projectID.value = '' + <%=takenProjectList.get(i).getProjectID() %>;
										submitForm('<portlet:namespace/>', 'takenProjectInfoForm', 'editProjectInfo', 'EmployeeStatInfo.jsp');
									">
										<%=takenProjectList.get(i).getName() %>
									</a>
								</td>
								<td align="left" valign="middle"><%=takenProjectList.get(i).getDepartName() %></td>
								<td align="left" valign="middle"><%=takenProjectList.get(i).getStartDate() %></td>	
								<td align="left" valign="middle"><%=takenProjectList.get(i).getEndDate() %></td>
								<td align="left" valign="middle"><%=takenProjectList.get(i).getRole() %></td>
								<td align="left" valign="middle"><%=takenProjectList.get(i).getLanguages() %></td>
								<td align="left" valign="middle"><%=takenProjectList.get(i).getFrameTech() %></td>
								<td align="left" valign="middle"><%=takenProjectList.get(i).getDBMS() %></td>
								<td align="left" valign="middle"><%=takenProjectList.get(i).getDescription() %></td>
								<td align="center" valign="middle">
									<a 	href="#" onclick="
										document.forms['<portlet:namespace/>takenProjectInfoForm'].projectID.value = '' + <%=takenProjectList.get(i).getProjectID() %>;
										submitForm('<portlet:namespace/>', 'takenProjectInfoForm', 'editTakenProject', 'EmployeeStatInfo.jsp');
									">
										Edit
									</a>
								</td>								
							</tr>
							<%} %>
							<tr>
								<td colspan="10" align="left" valign="middle">
									<input type="button" value="Add" onclick="
										submitForm('<portlet:namespace/>','takenProjectInfoForm','addTakenProject','EmployeeStatInfo.jsp')" />
									<input type="button" name="projectDelete" style="visibility:hidden" value="Delete" onclick="
										this.form.deleteProjectList.value = this.form.deleteProjectList.value.substr(1);
										submitForm('<portlet:namespace/>','takenProjectInfoForm','deleteTakenProject','EmployeeStatInfo.jsp');
									"/>
								</td>
							</tr>
						</table>
					</form>
					</td>
				</tr>
			</table>			
		</td>
	</tr>
	<tr>
		<td>&nbsp;</td>
	</tr>
</table>
</body>
</html>